SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Agurto,Jorge>
-- Create date: <11,10,2011>
-- =============================================
CREATE PROCEDURE [GOOGLECODERS].PostnetGetDisponibles
    @Marca varchar(50) = '',
    @Modelo varchar(50) = '',
    @NroSerie int = 0,
    @QueryUnions varchar(2000) = ''
AS
BEGIN

    DECLARE @TableAux TABLE (
    IdPostnet INT NOT NULL)

	DECLARE @TableAux2 TABLE (
    IdPostnet INT NOT NULL)
   
    INSERT INTO @TableAux (IdPostnet)
    EXEC(@QueryUnions)

	INSERT INTO @TableAux2 (IdPostnet)
    (SELECT DISTINCT IdPostnet
        FROM GOOGLECODERS.Postnet_x_Beneficiario)
	UNION(SELECT IdPostnet FROM @TableAux)

    SELECT IdPostnet,
        Marca,
        Modelo
    FROM [GOOGLECODERS].[Postnet] p
    WHERE
    p.IdPostnet
        NOT IN (SELECT IdPostnet FROM @TableAux2)
    AND (@Marca = '' or Marca like '%'+@Marca+'%')
    AND (@Modelo = '' or Modelo like '%'+@Modelo+'%')
    AND (@NroSerie = 0 or IdPostnet = @NroSerie)
END
GO
/*
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Agurto,Jorge>
-- Create date: <11,10,2011>
-- =============================================
CREATE PROCEDURE [GOOGLECODERS].PostnetGetDisponibles
AS
BEGIN
	SELECT IdPostnet,
		Marca,
		Modelo
	FROM [GOOGLECODERS].[Postnet] p
	WHERE
		p.IdPostnet
	NOT IN (
	SELECT IdPostnet
	FROM GOOGLECODERS.Postnet_x_Beneficiario
	GROUP BY IdPostnet)
END
GO
*/